;
(function (call) {
    var main = {
        mapId: "tjMap",
        productList: [
            {proId:"WTRV",name:"风 + 温度 + 湿度 + 散度", selected: true, "content":[
                {"list_id" : "EDA","unit":"风(风羽,m/s) ", "list_text" : "风","color":"black"},
                {"list_id" : "TMP","unit":" + 温度(红色等值线,℃) ", "list_text" : "温度","color":"red"},
                {"list_id" : "RH","unit":" + 湿度(色斑,%) ", "list_text" : "湿度","color":"mediumaquamarine"},
                {"list_id" : "DIV","unit":" + 散度(黑色等值线,1/s) ", "list_text" : "散度","color":"#000000"}
            ]},
            {proId:"WTRW",name:"风 + 温度 + 相对湿度 + 垂直速度","content":[
                {"list_id" : "EDA","unit":"风(风羽,m/s) ", "list_text" : "风","color":"black"},
                {"list_id" : "TMP","unit":" + 温度(红色等值线,℃) ", "list_text" : "温度","color":"red"},
                {"list_id" : "RH","unit":" + 相对湿度(色斑,%)", "list_text" : "相对湿度","color":"mediumaquamarine"},
                {"list_id" : "W","unit":" + 垂直速度(蓝色等值线,pa/s)", "list_text" : "垂直速度","color":"#3392e9"}
            ]},
            {proId:"WTH",name:"风 + 温度 + 500hPa高度","content":[
                {"list_id" : "EDA","unit":"风(风羽,m/s) ", "list_text" : "风","color":"black"},
                {"list_id" : "TMP","unit":" + 温度(红色等值线,℃) ", "list_text" : "温度","color":"red"},
                {"list_id" : "500hPa","unit":" + 500hPa高度(黑色等值线,10gpm)", "list_text" : "500hPa高度","color":"black"}
            ]},
            {proId:"WTR",name:"风 + 温度 + 500hPa相对湿度","content":[
                {"list_id" : "EDA","unit":"风(风羽,m/s) ", "list_text" : "风","color":"black"},
                {"list_id" : "TMP","unit":" + 温度(红色等值线,℃) ", "list_text" : "温度","color":"red"},
                {"list_id" : "500hPa","unit":" + 500hPa相对湿度(黑色等值线,%)", "list_text" : "500hPa相对湿度","color":"#000000"}
            ]},
            {proId:"DPT",name:"温度露点差 + 海平面气压 + 2m温度","content":[
                {"list_id" : "DEPR","unit":" 温度露点差(色斑,℃)", "list_text" : "露点温度差","color":"darkviolet"},
                {"list_id" : "PRMSL","unit":" + 海平面气压(黑色等值线,hPa)", "list_text" : "海平面气压","color":"black"},
                {"list_id" : "TMP2M","unit":" + 2m温度(红色等值线,℃)", "list_text" : "2m温度","color":"red"}
            ]},
            {proId:"WTQW",name:"风 + 温度 + 比湿+ 垂直速度","content":[
                {"list_id" : "EDA","unit":"风(风羽,m/s) ", "list_text" : "风","color":"black"},
                {"list_id" : "TMP","unit":" + 温度(红色等值线,℃) ", "list_text" : "温度","color":"red"},
                {"list_id" : "Q","unit":" + 比湿(色斑,g/kg)", "list_text" : "比湿","color":"mediumaquamarine"},
                {"list_id" : "W","unit":" + 垂直速度(蓝色等值线,pa/s)", "list_text" : "垂直速度","color":"#3392e9"}
            ]}
        ],
        cityListCfg: [
            { name: '市台', x: '117.200', y: '39.070', stationId: "54517", selected: true},
            { name: '宝坻', x: '117.343', y: '39.622', stationId: "54525" },
            { name: '北辰', x: '117.127', y: '39.278', stationId: "54528" },
            { name: '汉沽', x: '117.613', y: '39.109', stationId: "54530" },
            { name: '塘沽', x: '117.613', y: '39.109', stationId: "54623" },
            { name: '大港', x: '117.613', y: '39.109', stationId: "54645" },
            { name: '东丽', x: '117.361', y: '39.137', stationId: "54526" },
            { name: '蓟州', x: '114.516', y: '39.647', stationId: "54428" },
            { name: '津南', x: '117.372', y: '38.918', stationId: "54622" },
            { name: '静海', x: '116.931', y: '38.903', stationId: "54619" },
            { name: '宁河', x: '117.731', y: '39.392', stationId: "54529" },
            { name: '武清', x: '117.027', y: '39.418', stationId: "54523" },
            { name: '西青', x: '116.984', y: '39.153', stationId: "54527" },
            { name: '北京市区', x: '116.120', y: '39.920', stationId: "54511" },
        ],
        router: {
            // timeProfile: '/drawmake/makeprofile/timeProfile',
            timeProfile: '/TJ/zhfx/szyb/profile/getProducts.do',
        },
        init: function () {
            this.initDatePicker();
            this.initPointData();
            this.initProduct();
            this.bindEvt();
        },
        // 初始化时间控件
        initDatePicker: function () {
            var that = this;
            var time = $("#modal_point_pro").data('time');
            var date = new Date(time + ":00");
            //date.setHours(date.getHours() - 12);
            time = date.format("yyyy-MM-dd hh:mm");
            that.datepicker = CafeJS.Datepicker({
                curDate: time,
                appendTo: "#pointProfile-datepicker",
                dateFmt: "yyyy-MM-dd",
                type: 5,
                timeInterval: 12,
                dateType: 'H',
                customHm: [8, 20],
                call: function () {
                    that.getPointData();
                },
            });
        },
        // 初始化点剖页面基本信息
        initPointData: function () {
            var that = this;
            var x = $("#modal_point_pro").data('x');
            var y = $("#modal_point_pro").data('y');
            $(".lonWrap input").val(x);
            $(".latWrap input").val(y);
            var $city = $(".city-tab");
            that.cityListCfg.forEach(function (item) {
                var $item = $(`<div>${item.name}</div>`)
                $item.data('item', item);
                if(item.selected){
                    $item.addClass("active");
                }
                $city.append($item);
            })
        },
        //初始化类型
        initProduct: function () {
            var that = this;
            var $product = $('.vrm-items');
            that.productList.forEach(function (item) {
                if (item.selected) {
                    var div = '<div class="active productName">' + item.name + '</div>'
                } else {
                    var div = '<div class="productName">' + item.name + '</div>'
                }
                var $div = $(div);
                $div.data('item', item);
                $product.append($div);
            })
        },
        buildTitle: function () {
            var that = this;
            var pro = $(".vrm-items div.active").data('item');
            var startTime = new Date(that.datepicker.getVal());
            var agings = $("#postSelect").val();
            var endTime;
            if(agings == "000-072"){
                endTime = new Date(startTime.getTime() + (72 * 60 * 60 * 1000));
            }else{
                endTime = new Date(startTime.getTime() + (240 * 60 * 60 * 1000));
                startTime = new Date(startTime.getTime() + (72 * 60 * 60 * 1000));
            }
            var station = $(".city-tab .active").data("item");
            var title = startTime.format('yyyy-MM-dd hh:mm') + "至" + endTime.format('yyyy-MM-dd hh:mm') + " " + station.name + "站";
            var unit = "";
            pro.content.forEach(contentItem => {
                unit += '<span style="color: ' + contentItem.color + '">' + contentItem.unit + '</span>';
            });
            $(".vrm-bottom-charts-title").text(title);
            $(".vrm-bottom-charts-unit").html(unit);
        },
        getPointData: function () {
            var that = this;
            that.buildTitle();
            var pro = $(".vrm-items div.active").data('item');
            var time = new Date(that.datepicker.getVal()).format('yyyy-MM-dd hh:mm');
            // var mode = $(".product-szyb-tab div:first-child div ul li.active").text();
            var station = $(".city-tab .active").data("item");
            var agings = $("#postSelect").val();
            var params = {
                productID: pro.proId,
                queryTime: time,
                areaCD: agings,
                station: station.stationId,
                //modeTye: "ECMF",
				modeTye : $(".product-szyb-tab li.active").data().model.fullname == "EC" ? "ECMF":$(".product-szyb-tab li.active").data().model.fullname
            }
            loading.add();
            $.post(that.router.timeProfile, params, function (res) {
                loading.remove();
                if(res.success){
                    let proImg = res.params.data.url;
                    if(proImg){
                        proImg = proImg.substring(proImg.indexOf("/tjfile"), proImg.length);
                    }
                    let legendImg = res.params.data.legendUrl;
                    if(legendImg){
                        legendImg = legendImg.substring(legendImg.indexOf("/tjcmaps"), legendImg.length);
                        $(".vrm-bottom-charts-pic-legend").show();
                    }else{
                        $(".vrm-bottom-charts-pic-legend").hide();
                    }
                    $(".vrm-bottom-charts-pic").attr("src", proImg);
                    $(".vrm-bottom-charts-pic-legend").attr("src", legendImg);
                }
                // $(".vrm-bottom-charts").empty().append(`<img src="data:img/png;base64,${res}" id="lineProfileDownLoad" class="lineProfile-imgPath">`)
            })
        },
        downImg: function () {
            var url = $(".vrm-bottom-charts img").attr('src');
            $("#pointImg").attr('href', url);
            $("#pointImg")[0].click();
        },
        bindEvt: function () {
            var that = this;
            $(".vrm-items").on('click', 'div.productName', function () {
                $(this).addClass('active').siblings().removeClass('active')
                that.getPointData();
            })
            $('.download').click(function () {
                Html2Canvas.Save($(".vrm-bottom-charts"), function () { }, $(".vrm-bottom-charts-title").text());
                // that.downImg();
            })
            $(".city-tab").on('click', 'div', function () {
                $(this).addClass('active').siblings().removeClass('active')
                var item = $(this).data('item');
                $(".lonWrap input").val(item.x);
                $(".latWrap input").val(item.y);
                that.getPointData();
            })
            $(".selectBtn").click(function () {
                that.getPointData();
            })
            $("#postSelect").change(function () {
                that.getPointData();
            })
            $(".pointBtn").click(function () {
                //$("#modal_point_pro .close").click();
                $("#modal_point_pro").remove();
                //$(".point").click();
            })
            $('.vrm-items div').eq(0).click();
        }
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function (main) {
    main.init();
});